//package com.yanfan.ba;
//
//import com.serotonin.bacnet4j.LocalDevice;
//import com.serotonin.bacnet4j.RemoteDevice;
//import com.serotonin.bacnet4j.exception.BACnetException;
//import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
//import com.serotonin.bacnet4j.npdu.ip.IpNetworkBuilder;
//import com.serotonin.bacnet4j.transport.DefaultTransport;
//import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
//import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;
//import com.serotonin.bacnet4j.util.RequestUtils;
//import lohbihler.warp.WarpClock;
//import lombok.SneakyThrows;
//
//import java.net.InetSocketAddress;
//import java.util.List;
//
//public class test {
//    public BacNetBean bbmd() throws Exception {
//        IpNetwork ipNetwork = new IpNetworkBuilder()
//                .withLocalBindAddress("192.168.2.7") //
//                .withSubnet("255.255.255.0", 24)
//                .withPort(47808)
//                .withReuseAddress(true)
//                .build();
//        ipNetwork.enableBBMD();
//        LocalDevice initialize = new LocalDevice(10000, new DefaultTransport(ipNetwork))
//                .withClock( new WarpClock()) //
//                .initialize();
//        BacNetBean bacNetBean = new BacNetBean();
//        bacNetBean.setLocalDevice(initialize);
//        bacNetBean.setIpNetwork(ipNetwork);
//        return bacNetBean;
//    }
//
//
//    @SneakyThrows
//    @Test
//    public void test() throws BACnetException {
//        BacNetBean bacNetBean = bbmd1();
//        IpNetwork ipNetwork = bacNetBean.getIpNetwork();
//        // 注册为外部设备就是 BBMD 这里的IP 指向的是 BBMD 设备的IP
//        // 这样我们就可以夸网段读取了
//        ipNetwork.registerAsForeignDevice(new InetSocketAddress("172.17.14.50", 47808), 10000000);
//        // 点位的概念，一个点位可以理解为 一个按钮，里面有多个回路，多个灯泡，通过这一个点位去控制
//        LocalDevice localDevice = bacNetBean.getLocalDevice();
//        // 获取远程设备，instanceNumber 是设备的device id
//        RemoteDevice remoteDevice = localDevice.getRemoteDeviceBlocking(127001);
//        log.info("获取模型名称：{}", remoteDevice.getDeviceProperty(PropertyIdentifier.modelName));
//        log.info("获取模型名称：{}", remoteDevice.getDeviceProperty(PropertyIdentifier.objectName));
//        // 所有的点位
//        List<ObjectIdentifier> objectList = RequestUtils.getObjectList(localDevice, remoteDevice).getValues();
//        for (ObjectIdentifier objectIdentifier : objectList) {
//            System.out.println("点位类型：" + objectIdentifier.getObjectType() + "----"
//                    + "对象实例" + objectIdentifier.getInstanceNumber());
//        }
//        log.info("共计点位：{}", objectList.size());
//        // 根据指定点位获取
//        // ObjectIdentifier oid = new ObjectIdentifier(ObjectType.analogInput, 1);
//        //获取指定的presentValue
//        // PropertyValues pvs2 = RequestUtils.readOidPresentValues(localDevice, remoteDevice, Arrays.asList(oid), null);
//        // System.out.println("analogInput:1 == " + pvs2.get(oid, PropertyIdentifier.presentValue));
//        localDevice.terminate();
//    }
//
//}
//
